package bb.lanxing.devicelist;

import android.app.Application;
import androidx.lifecycle.MutableLiveData;
import bb.lanxing.lib.devices.api.provider.CadenceProvider;
import bb.lanxing.lib.devices.api.provider.HeartRateProvider;
import bb.lanxing.lib.devices.api.provider.SpeedProvider;
import bb.lanxing.lib.devices.core.provider.DataProviders;
import bb.lanxing.model.database.Device;
//import bb.lanxing.mvvm.base.viewmodel.BaseViewModel;
import java.util.List;
import kotlin.Deprecated;
import kotlin.Metadata;
import kotlin.Pair;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

@Deprecated(message = "蓝行不需要这个vm分发，用DisplayPoint")

public final class BleSensorDataViewModel /*extends BaseViewModel*/ {
    public static final Companion Companion = new Companion(null);
    public static final long MAX_DATA_VALIDITY = 2000;
    private final CadenceProvider.CadenceDataListener cadenceDataListener;
    private final MutableLiveData<Pair<Integer, Integer>> cadenceLiveData;
    private final HeartRateProvider.HeartRateDataListener heartRateDataListener;
    private final MutableLiveData<Pair<Integer, Integer>> heartRateLiveData;
    private final SpeedProvider.SpeedDataListener speedListener;
    private final MutableLiveData<Integer> speedLiveData;

    public BleSensorDataViewModel(Application application) {
        super();
        Intrinsics.checkNotNullParameter(application, "application");
        this.cadenceLiveData = new MutableLiveData<>();
        this.heartRateLiveData = new MutableLiveData<>();
        this.speedLiveData = new MutableLiveData<>();
        CadenceProvider.CadenceDataListener cadenceDataListener = new CadenceProvider.CadenceDataListener() {
            @Override
            public void onRawCadenceData(int i, long j, long j2) {
            }

            @Override
            public void onCalculatedCadenceData(int i, int i2) {
                BleSensorDataViewModel.this.getCadenceLiveData().postValue(new Pair<>(i, i2));
            }
        };
        this.cadenceDataListener = cadenceDataListener;
        HeartRateProvider.HeartRateDataListener heartRateDataListener = new HeartRateProvider.HeartRateDataListener() {
            @Override
            public void onCloseHeartRateWarn(boolean z) {
            }

            @Override
            public void onInitHeartRateBelt(boolean z, int i) {
            }

            @Override
            public void onSetHeartRateWarnStatus(boolean z) {
            }

            @Override
            public void onHeartRate(int i, String address, int i2) {
                Intrinsics.checkNotNullParameter(address, "address");
                BleSensorDataViewModel.this.getHeartRateLiveData().postValue(new Pair<>(i, i2));
            }
        };
        this.heartRateDataListener = heartRateDataListener;
        SpeedProvider.SpeedDataListener speedDataListener = new SpeedProvider.SpeedDataListener() {
            @Override
            public void onRawSpeedData(int i, long j, long j2) {
            }

            @Override
            public void onCalculatedSpeedData(int i, int i2) {
                BleSensorDataViewModel.this.getSpeedLiveData().postValue(i2);
            }
        };
        this.speedListener = speedDataListener;
        DataProviders.getCadenceProvider().registerDataListener(cadenceDataListener);
        DataProviders.getHeartrateProvider().registerDataListener(heartRateDataListener);
        DataProviders.getSpeedProvider().registerDataListener(speedDataListener);
    }

    public final MutableLiveData<Pair<Integer, Integer>> getCadenceLiveData() {
        return this.cadenceLiveData;
    }

    public final MutableLiveData<Pair<Integer, Integer>> getHeartRateLiveData() {
        return this.heartRateLiveData;
    }

    public final MutableLiveData<Integer> getSpeedLiveData() {
        return this.speedLiveData;
    }

    /*@Override
    public void onCleared() {
        DataProviders.getCadenceProvider().unregisterDataListener(this.cadenceDataListener);
        DataProviders.getHeartrateProvider().unregisterDataListener(this.heartRateDataListener);
        DataProviders.getSpeedProvider().unregisterDataListener(this.speedListener);
    }*/

    public static final class Companion {
        public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }
    }


    public final List<Device> getBoundedSensorDevices() {
        List<Device> devicesByLogicType = Device.getDevicesByLogicType(1000);
        Intrinsics.checkNotNullExpressionValue(devicesByLogicType, "getDevicesByLogicType(SmartDevice.TYPE_SENSORS)");
        return devicesByLogicType;
    }
}
